package com.rapida.example;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.rapida.db.SQLiteFactory;
import com.rapida.framwork.IBOutlet;
import com.rapida.framwork.IVOutlet;
import com.rapida.framwork.UIViewController;

/**
 * Created by mm on 2015/1/19.
 */
@IVOutlet(id = R.layout.theme)
public class MainUIController extends UIViewController implements AdapterView.OnItemClickListener {
	@IBOutlet(id=R.id.list)
	private ListView mThemeList;
	@IBOutlet(id=R.id.background)
	private View mBgView;
	private ArrayAdapter mAdapter;
	private ExampleActivity mActivity;

	public MainUIController(ExampleActivity activity) {
		mActivity = activity;
		SQLiteFactory.init(activity);

		Person p = new Person(activity);
		p.id = "10010";
		p.name = "中国联通";
		p.save();

		//SQLiteFactory.delAll(Person.class);
		//SQLiteFactory.findAll(Person.class, "_index=?", new String[]{"10010"});
	}

	@Override
	public void viewDidLoad() {
		mAdapter = new ArrayAdapter<Person>(mActivity, android.R.layout.simple_list_item_1, SQLiteFactory.findAll(Person.class));
		mThemeList.setAdapter(mAdapter);
		mThemeList.setOnItemClickListener(this);
	}

	@Override
	public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
	}
}
